package com.itheima.sh.exception;


import com.itheima.sh.response.StatusCode;
import org.springframework.util.StringUtils;

/**
 * @author win10
 */
public class ExceptionCast {

    /**
     * 抛出自定义异常
     */
    public static void assertNullInteger(Integer code, String message) {
        throw new BusinessException(code, message);
    }

    public static void assertNullString(String str, String message) {
        if (StringUtils.isEmpty(str)) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertNullInteger(String[] str, String message) {
        if (StringUtils.isEmpty(str)) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertNullSize(Integer size, String message) {
        if (size == 0) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertBoolean(Boolean b, String message) {
        if (b) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }
}
